#!/bin/bash

# Script adapted from upstream supabase-postgres
# https://github.com/supabase/postgres/blob/develop/ansible/files/admin_api_scripts/pg_upgrade_pgsodium_getkey.sh

set -euo pipefail

KEY_FILE=/opt/bitnami/postgresql/conf/pgsodium_root.key

# if key file doesn't exist (project previously didn't use pgsodium), generate a new key
if [[ ! -f "${KEY_FILE}" ]]; then
    head -c 32 /dev/urandom | od -A n -t x1 | tr -d ' \n' >$KEY_FILE
fi

cat $KEY_FILE
